using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WPCoco.Tasks
{
    public abstract class EaseTask : FiniteTime, IContainer<Task>
    {
        public EaseTask(FiniteTime task, EaseFunction function)
            : base(task.Duration)
        {
            if (task == null)
                throw new NullReferenceException("task");
            if (function == null)
                throw new NullReferenceException("function");
            innerTask = task; this.function = function;
        }

        FiniteTime innerTask;

        public FiniteTime InnerTask
        {
            get { return innerTask; }
            private set { innerTask = value; }
        }

        EaseFunction function;

        public override void Initialize()
        {
            base.Initialize();
            Duration = innerTask.Duration;
            innerTask.Initialize();
        }

        public override void Update(float time)
        {
            base.Update(time);
            float newtime = function.Evaluate(time / Duration) * Duration;
            innerTask.Update(newtime);
        }

        #region IContainer<Task> Members

        public IEnumerable<Task> GetContainerEnumerator()
        {
            yield return innerTask;
            yield break;
        }

        #endregion
    }
}
